package study.dq.jms.filter;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author dongqun
 * @version 1.0
 * @description 类的功能描述
 * @date 2019/11/22 16:47
 */
public class CAFD implements MessageListener {

    public CAFD() {
        try {
            ConnectionFactory factory = new ActiveMQConnectionFactory("admin", "admin", "tcp://127.0.0.1:61616");
            QueueConnection connection = ((ActiveMQConnectionFactory) factory).createQueueConnection();
            QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue("Combat_Intelligence");
            String filter = "COMBAT_LEVEL = 3";
            QueueReceiver receiver = session.createReceiver(queue, filter);
            receiver.setMessageListener(this);
            connection.start();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onMessage(Message message) {
        try {
            TextMessage textMessage = (TextMessage) message;
            System.out.println("收到指令：" + textMessage.getText());
            System.out.println("县委华政委分析战报......");
            System.out.println("绥德县武装部命令：民兵在村后头集合");
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        CAFD cmc = new CAFD();
    }
}
